package com.ryan.chat.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ryan.chat.service.ChatAiService;

/**
 * @author 308039
 * @version 1.0.0
 * @type ChatAiController.java
 * @description
 * @date 2024/10/22 20:09
 */
@RestController
@RequestMapping("chat")
public class ChatAiController {

    @Autowired
    private ChatAiService chatAiService;

    @PostMapping("/chatai")
    public Map<String, String> chatAi(String prompt) {
        Map<String, String> restMap = new HashMap<>();
        String message = chatAiService.chatHuluAi(Optional.ofNullable(prompt).orElse("使用 ts 语言打印 helloworld"));
        restMap.put("message", message);
        return restMap;
    }

    @DeleteMapping("/reset")
    public String deleteCHatHistory() {
        Map<String, String> restMap = new HashMap<>();

        return chatAiService.deleteChatHistory();
    }

}
